import type {App} from "vue";
import {createRouter, createWebHashHistory, type RouteRecordRaw} from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由(即不需要权限的路由，任务人登录进来都不需要权限)
export const constantRoutes: RouteRecordRaw[] = [
  // 首页
  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "Dashboard",
        meta: {
          title: "dashboard",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error/401.vue"),
        meta: {hidden: true},
      },
      {
        path: "404",
        component: () => import("@/views/error/404.vue"),
        meta: {hidden: true},
      },
      {
        path: "profile",
        name: "Profile",
        component: () => import("@/views/profile/index.vue"),
        meta: {title: "个人中心", icon: "user", hidden: true},
      },
      {
        path: "my-notice",
        name: "MyNotice",
        component: () => import("@/views/system/notice/components/MyNotice.vue"),
        meta: {title: "我的通知", icon: "user", hidden: true},
      },
    ],
  },
  {
    path: "/redirect",
    component: Layout,
    meta: {hidden: true},
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },


  // 会员管理
  {
    path: "/users",
    component: Layout,
    children: [
      {
        path: "",
        component: () => import("@/views/user/index.vue"),
        meta: {
          title: "userManagerL",
          icon:"el-icon-User"
        },
      },
    ],
  },

  // 文章管理（分类列表-文章列表-标签列表）
  {
    path: "/articleManager",
    component: Layout,
    meta: {
      title: "articleManager",
      icon:"el-icon-Management"
    },
    children: [
      {
        path: "article",
        component: () => import("@/views/article/index.vue"),
        meta: {
          title: "articleList",
          icon:"el-icon-Document"
        },
      },
      {
        path: "category",
        component: () => import("@/views/category/index.vue"),
        meta: {
          title: "cateList",
          icon: "el-icon-Expand",
        },
      },

      {
        path: "tag",
        component: () => import("@/views/tag/index.vue"),
        meta: {
          title: "tagList",
          icon: "el-icon-Postcard",
        },
      },

      {
        path: "echart",
        component: () => import("@/views/echart/index.vue"),
        meta: {
          title: "statisticalChart",
          icon: "el-icon-pieChart",
        },
      },
    ],
  },

  // 图片管理
  {
    path: "/img",
    component: Layout,
    children: [
      {
        path: "",
        component: () => import("@/views/img/index.vue"),
        meta: {
          title: "imgSet",
          icon:"el-icon-picture"
        },
      },
    ],
  },

  // 管理员
  {
    path: "/admin",
    component: Layout,
    children: [
      {
        path: "",
        component: () => import("@/views/admin/index.vue"),
        meta: {
          title: "adminSet",
          icon:"el-icon-Tools"
        },
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    // hidden: true 不展示在后台左侧菜单中
    meta: {hidden: true},
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({left: 0, top: 0}),
});

// 全局注册 router
export function setupRouter(app: App<Element>) {
  app.use(router);
}

export default router;
